home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
033a
/
aed244a.zip
/
FINDWORD.ASM
< prev
next >
Wrap
Assembly Source File
|
1991-02-16
|
5KB
|
135 lines
comment @
* FINDWORD
*----------------------------------------------------------------------------
*
* Routine to find the next (direction = 1) or previous (direction = 0)
* word position in a QuickBASIC string
*
* Author: Tom Collins
* 09-20-90
*
* Typical Calling Sequence:
*
* WordPos% = 1
* A$ = "This is a test"
* CALL FindWord(A$ ,1 ,WordPos%)
*
* Assemble with: TASM upcase.asm [/Zi] or,
* MASM upcase.asm [/Zi]
* (Zi = Debug info for CV)
*
@
.MODEL MEDIUM, BASIC
.CODE
PUBLIC FINDWORD
FINDWORD proc USES es si di, STRDES:ptr, Direction:ptr, Z:ptr
; The registers are used as follows:
;
; AH = Direction flag
; BL = Z value
; BH = New return value
; CL = String length
; CH = Current string index in main loop
; DS:SI = Current string index + 1 address
push ds ; Save DS
pop es ; Set ES = DS
mov di, Direction ; DS:DI -> Direction indicator
mov ah, [di] ; AH = Direction
mov di, Z ; DS:DI -> Z value
mov bl, [di] ; BL = Where we're at now (Z value)
mov di, STRDES ; DS:DI -> String descriptor
mov cl, [di] ; Get string length in CL ( < 256, right?? )
mov si, [di+2] ; DS:SI -> String
mov ch, 1 ; CH = String index counter
; Test for invalid conditions
mov bh, bl ; Assume no change in Z value
and cl, cl ; Test string length
jz FW100 ; Null string. Return
cmp cl, bl ; See if we're starting past string end
jge FW00 ; No
and ah, ah ; Yes. Test the direction.
jnz FW100 ; Forward. Return
; mov bh, cl ; Backward. Set return value to str len + 1
; inc bh ;
; jmp FW100 ; Return
; Initialize the default return value based on the direction
FW00: mov bh, cl ; Assume string length + 1
inc bh ;
and ah, ah ; Set the flags
jnz FW01 ; Backwards
mov bh, 1 ; Backwards. Assume length of 1
; Main loop.
FW01: lodsb ; Get a character from string into AL
cmp al, ' ' ; Is it a space?
je FW02 ; Yes
cmp al, 0FAh ; Is is a soft space?
jne FW10 ; No
; Found a space or soft space. See what the next character is.
FW02: mov al, [si] ; Get next character
cmp al, ' ' ; Is it a space?
je FW10 ; Yes. Continue loop
cmp al, 0FAh ; Is is a soft space?
je FW10 ; Yes
; Found a word position. See which direction we're going in.
and ah, ah ;
jz FW04 ; Backwards
; Forward direction. If index > Z, set return value and exit. Otherwise,
; keep looking.
FW03: cmp ch, bl ; See if index > Z
jl FW10 ; No. Keep looking.
inc ch ; Yes. Save current index + 1 in return loc
mov bh, ch ;
jmp short FW100 ; Return
; Reverse direction. If we're >= Z, return. Otherwise set new value
; and look for the next word position.
FW04: push cx ; Save CX temporarily
inc ch ; Add one to CH for comparison
cmp ch, bl ; See if index < Z
pop cx ; Restore CX
jge FW100 ; Yes. Return
mov bh, ch ; No. Save current index + 1 in return loc
inc bh ;
jmp short FW10 ; Continue loop
; Continue loop while not at the end of the string
FW10: inc ch ; Increment string index
cmp cl, ch ; Test for equal to string length
jge FW01 ; Not equal. Continue loop.
; Return to the calling program
FW100: mov di, Z ; DS:DI -> Z
mov [di], bh ; Load return value
ret ; Return
FINDWORD endp
end